Passed
Push — master ( d761f4...ac4b4e )
by Gianluca
01:12
created

test.js ➔ ... ➔ describe(ꞌListꞌ)   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 171
Code Lines 43

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 43
c 1
b 0
f 0
nc 1
dl 0
loc 171
rs 8.8478
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
const chai = require('chai');
2
const expect = chai.expect;
3
const jsonPattern = require('chai-json-pattern');
4
const sinon = require('sinon');
5
const { Client: SDKClient } = require('../bin/index');
6
7
chai.use(jsonPattern.default);
8
9
// Test clients setup
10
var authenticatedTestClient = null;
11
var unauthenticatedTestClient = null;
12
async function getUnauthenticatedTestClient() {
13
    if (!unauthenticatedTestClient) {
14
        /** global: SDKClient */
15
        unauthenticatedTestClient = new SDKClient('http://localhost:3000');
0 ignored issues
show
Bug introduced by
The variable SDKClient seems to be never declared. If this is a global, consider adding a /** global: SDKClient */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
16
    }
17
18
    return unauthenticatedTestClient;
19
}
20
async function getAuthenticatedTestClient() {
21
    if (!authenticatedTestClient) {
22
        /** global: SDKClient */
23
        authenticatedTestClient = new SDKClient('http://localhost:3000');
0 ignored issues
show
Bug introduced by
The variable SDKClient seems to be never declared. If this is a global, consider adding a /** global: SDKClient */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
24
25
        const username = '[email protected]';
26
        const password = 'gian6280';
27
28
        await authenticatedTestClient.authenticate(username, password);
29
    }
30
31
    return authenticatedTestClient;
32
}
33
34
describe('Wrapper', function() {
35
    afterEach(() => {
36
        sinon.restore();
37
    });
38
39
    describe('Api Url', function() {
40
        it('should get default api url if no url is passed in constructor', function() {
41
            /** global: SDKClient */
42
            const client = new SDKClient();
0 ignored issues
show
Bug introduced by
The variable SDKClient seems to be never declared. If this is a global, consider adding a /** global: SDKClient */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
43
44
            expect(client.apiUrl).to.equal('https://api.proposalpage.com');
45
        });
46
        it('should get passed url if a url is passed in constructor', function() {
47
            /** global: SDKClient */
48
            const client = new SDKClient('https://example.com');
0 ignored issues
show
Bug introduced by
The variable SDKClient seems to be never declared. If this is a global, consider adding a /** global: SDKClient */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
49
50
            expect(client.apiUrl).to.equal('https://example.com');
51
        });
52
    });
53
54
    describe('Token', function() {
55
        it('should not have a default token set', function() {
56
            /** global: SDKClient */
57
            const client = new SDKClient();
0 ignored issues
show
Bug introduced by
The variable SDKClient seems to be never declared. If this is a global, consider adding a /** global: SDKClient */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
58
59
            expect(client.token).to.be.undefined;
0 ignored issues
show
introduced by
The result of the property access to expect(client.token).to.be.undefined is not used.
Loading history...
60
        });
61
        it('should get the token that has been set', function() {
62
            /** global: SDKClient */
63
            const client = new SDKClient();
0 ignored issues
show
Bug introduced by
The variable SDKClient seems to be never declared. If this is a global, consider adding a /** global: SDKClient */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
64
65
            client.token = 'token';
66
67
            expect(client.token).to.equal('token');
68
        });
69
    });
70
});
71
72
describe('Api Responses', function() {
73
    afterEach(() => {
74
        sinon.restore();
75
    });
76
77
    describe('Auth', function() {
78
        describe('Token', function() {
79
            it('should return token', async function() {
80
                const client = await getUnauthenticatedTestClient();
81
82
                const username = '[email protected]';
83
                const password = 'teste';
84
85
                const response = await client.authenticate(username, password);
86
87
                expect(response.statusCode).to.equal(200);
88
                expect(response.json).to.matchPattern(`{
89
                    "token": String,
90
                }`);
91
            });
92
        });
93
94
        describe('Me', function() {
95
            it('should return logged user id', async function() {
96
                const client = await getAuthenticatedTestClient();
97
                const response = await client.authMe();
98
99
                expect(response.statusCode).to.equal(200);
100
                expect(response.json).to.matchPattern(`{
101
                    "id": String,
102
                }`);
103
            });
104
        });
105
    });
106
107
    describe('Project', function() {
108
        var testProjectId = null;
109
110
        describe('Create', function() {
111
            it('should create and return a project', async function() {
112
                const client = await getAuthenticatedTestClient();
113
                const response = await client.createProject({
114
                    title: 'New Project',
115
                    blocks: [],
116
                });
117
118
                const responseBody = response.json;
119
120
                expect(response.statusCode).to.equal(201);
121
                expect(responseBody).to.matchPattern(`{
122
                    "_id": String,
123
                    "title": String,
124
                    "fonts": Array,
125
                    "publish": Boolean,
126
                    "secure": Boolean,
127
                    "countViews": Number,
128
                    "timeViews": Number,
129
                    "priority": Number,
130
                    "blocks": Array,
131
                    "userId": String,
132
                    "accountId": String,
133
                    "token": String,
134
                    "slug": String,
135
                    "publishURL": String,
136
                    "createdAt": String,
137
                    "updatedAt": String,
138
                    "__v": Number,
139
                }`);
140
                expect(responseBody.title).to.equal('New Project');
141
                expect(responseBody.blocks).to.be.empty;
0 ignored issues
show
introduced by
The result of the property access to expect(responseBody.blocks).to.be.empty is not used.
Loading history...
142
143
                testProjectId = responseBody._id;
144
            });
145
        });
146
147
        describe('List', function() {
148
            it('should list user projects paginated', async function() {
149
                const client = await getAuthenticatedTestClient();
150
                const response = await client.listProjects();
151
152
                const responseBody = response.json;
153
                const projects = responseBody.items;
154
155
                expect(response.statusCode).to.equal(200);
156
                expect(responseBody).to.matchPattern(`{
157
                    "items": Array,
158
                    "totalItems": Number,
159
                    "page": Number,
160
                    "limit": Number,
161
                    "pages": Number,
162
                    "defaultCover": String,
163
                }`);
164
                projects.forEach(project => {
165
                    expect(project).to.matchPattern(`{
166
                        "_id": String,
167
                        "title": String,
168
                        "fonts": Array,
169
                        "publish": Boolean,
170
                        "secure": Boolean,
171
                        "countViews": Number,
172
                        "timeViews": Number,
173
                        "priority": Number,
174
                        "blocks": Array,
175
                        "userId": String,
176
                        "accountId": String,
177
                        "token": String,
178
                        "slug": String,
179
                        "publishURL": String,
180
                        "createdAt": String,
181
                        "updatedAt": String,
182
                        "__v": Number,
183
                        "password"?: String OR null,
184
                        "lastView"?: String,
185
                    }`);
186
                });
187
            });
188
189
            it('should list user projects paginated in a specific page', async function() {
190
                const client = await getAuthenticatedTestClient();
191
                const response = await client.listProjects(2, 3);
192
193
                const responseBody = response.json;
194
                const projects = responseBody.items;
195
196
                expect(response.statusCode).to.equal(200);
197
                expect(responseBody).to.matchPattern(`{
198
                    "items": Array,
199
                    "totalItems": Number,
200
                    "page": Number,
201
                    "limit": Number,
202
                    "pages": Number,
203
                    "defaultCover": String,
204
                }`);
205
                expect(responseBody.page).to.equal(2);
206
                expect(responseBody.limit).to.equal(3);
207
                projects.forEach(project => {
208
                    expect(project).to.matchPattern(`{
209
                        "_id": String,
210
                        "title": String,
211
                        "fonts": Array,
212
                        "publish": Boolean,
213
                        "secure": Boolean,
214
                        "countViews": Number,
215
                        "timeViews": Number,
216
                        "priority": Number,
217
                        "blocks": Array,
218
                        "userId": String,
219
                        "accountId": String,
220
                        "token": String,
221
                        "slug": String,
222
                        "publishURL": String,
223
                        "createdAt": String,
224
                        "updatedAt": String,
225
                        "__v": Number,
226
                        "password"?: String OR null,
227
                        "lastView"?: String,
228
                    }`);
229
                });
230
            });
231
232
            it('should list user projects paginated with a specific quantity of items per page', async function() {
233
                const client = await getAuthenticatedTestClient();
234
                const response = await client.listProjects(2);
235
236
                const responseBody = response.json;
237
                const projects = responseBody.items;
238
239
                expect(response.statusCode).to.equal(200);
240
                expect(responseBody).to.matchPattern(`{
241
                    "items": Array,
242
                    "totalItems": Number,
243
                    "page": Number,
244
                    "limit": Number,
245
                    "pages": Number,
246
                    "defaultCover": String,
247
                }`);
248
                expect(responseBody.page).to.equal(2);
249
                projects.forEach(project => {
250
                    expect(project).to.matchPattern(`{
251
                        "_id": String,
252
                        "title": String,
253
                        "fonts": Array,
254
                        "publish": Boolean,
255
                        "secure": Boolean,
256
                        "countViews": Number,
257
                        "timeViews": Number,
258
                        "priority": Number,
259
                        "blocks": Array,
260
                        "userId": String,
261
                        "accountId": String,
262
                        "token": String,
263
                        "slug": String,
264
                        "publishURL": String,
265
                        "createdAt": String,
266
                        "updatedAt": String,
267
                        "__v": Number,
268
                        "password"?: String OR null,
269
                        "lastView"?: String,
270
                    }`);
271
                });
272
            });
273
274
            it('should list user projects paginated with a specific title search', async function() {
275
                const client = await getAuthenticatedTestClient();
276
                const response = await client.listProjects(1, 6, 'Project title that does not exist');
277
278
                const responseBody = response.json;
279
                const projects = responseBody.items;
280
281
                expect(response.statusCode).to.equal(200);
282
                expect(responseBody).to.matchPattern(`{
283
                    "items": Array,
284
                    "totalItems": Number,
285
                    "page": Number,
286
                    "limit": Number,
287
                    "pages": Number,
288
                    "defaultCover": String,
289
                }`);
290
                expect(responseBody.page).to.equal(1);
291
                expect(responseBody.limit).to.equal(6);
292
                expect(responseBody.items.length).to.equal(0);
293
                projects.forEach(project => {
294
                    expect(project).to.matchPattern(`{
295
                        "_id": String,
296
                        "title": String,
297
                        "fonts": Array,
298
                        "publish": Boolean,
299
                        "secure": Boolean,
300
                        "countViews": Number,
301
                        "timeViews": Number,
302
                        "priority": Number,
303
                        "blocks": Array,
304
                        "userId": String,
305
                        "accountId": String,
306
                        "token": String,
307
                        "slug": String,
308
                        "publishURL": String,
309
                        "createdAt": String,
310
                        "updatedAt": String,
311
                        "__v": Number,
312
                        "password"?: String OR null,
313
                        "lastView"?: String,
314
                    }`);
315
                });
316
            });
317
        });
318
319
        describe('Retrieve', function() {
320
            it('should retrieve a existing project', async function() {
321
                const client = await getAuthenticatedTestClient();
322
                const response = await client.listProject(testProjectId);
323
324
                expect(response.statusCode).to.equal(200);
325
                expect(response.json).to.matchPattern(`{
326
                    "_id": String,
327
                    "title": String,
328
                    "fonts": Array,
329
                    "publish": Boolean,
330
                    "secure": Boolean,
331
                    "countViews": Number,
332
                    "timeViews": Number,
333
                    "priority": Number,
334
                    "blocks": Array,
335
                    "userId": String,
336
                    "accountId": String,
337
                    "token": String,
338
                    "slug": String,
339
                    "publishURL": String,
340
                    "createdAt": String,
341
                    "updatedAt": String,
342
                    "__v": Number,
343
                    "password"?: String OR null,
344
                    "lastView"?: String,
345
                }`);
346
            });
347
        });
348
349
        describe('Update', function() {
350
            it('should update a existing project', async function() {
351
                const client = await getAuthenticatedTestClient();
352
                const response = await client.updateProject(testProjectId, {
353
                    title: 'Updated Project Title',
354
                });
355
356
                const responseBody = response.json;
357
358
                expect(response.statusCode).to.equal(200);
359
                expect(responseBody).to.matchPattern(`{
360
                    "_id": String,
361
                    "title": String,
362
                    "fonts": Array,
363
                    "publish": Boolean,
364
                    "secure": Boolean,
365
                    "countViews": Number,
366
                    "timeViews": Number,
367
                    "priority": Number,
368
                    "blocks": Array,
369
                    "userId": String,
370
                    "accountId": String,
371
                    "token": String,
372
                    "slug": String,
373
                    "publishURL": String,
374
                    "createdAt": String,
375
                    "updatedAt": String,
376
                    "__v": Number,
377
                }`);
378
                expect(responseBody.title).to.equal('Updated Project Title');
379
            });
380
        });
381
382
        describe('Clone', function() {
383
            it('should clone a project and return it', async function() {
384
                const client = await getAuthenticatedTestClient();
385
                const response = await client.cloneProject(testProjectId);
386
387
                const responseBody = response.json;
388
389
                expect(response.statusCode).to.equal(200);
390
                expect(responseBody).to.matchPattern(`{
391
                    "_id": String,
392
                    "title": String,
393
                    "fonts": Array,
394
                    "publish": Boolean,
395
                    "secure": Boolean,
396
                    "countViews": Number,
397
                    "timeViews": Number,
398
                    "priority": Number,
399
                    "blocks": Array,
400
                    "userId": String,
401
                    "accountId": String,
402
                    "token": String,
403
                    "slug": String,
404
                    "publishURL": String,
405
                    "createdAt": String,
406
                    "updatedAt": String,
407
                    "__v": Number,
408
                    "password"?: String,
409
                }`);
410
                expect(responseBody.title).to.equal('Updated Project Title');
411
                expect(responseBody.blocks).to.be.empty;
0 ignored issues
show
introduced by
The result of the property access to expect(responseBody.blocks).to.be.empty is not used.
Loading history...
412
            });
413
        });
414
415
        describe('Password', function() {
416
            it('should set project password', async function() {
417
                const client = await getAuthenticatedTestClient();
418
                const response = await client.setProjectPassword(testProjectId, 'password');
419
420
                const responseBody = response.json;
421
422
                expect(response.statusCode).to.equal(200);
423
                expect(responseBody).to.matchPattern(`{
424
                    "_id": String,
425
                    "title": String,
426
                    "fonts": Array,
427
                    "publish": Boolean,
428
                    "secure": Boolean,
429
                    "countViews": Number,
430
                    "timeViews": Number,
431
                    "priority": Number,
432
                    "blocks": Array,
433
                    "userId": String,
434
                    "accountId": String,
435
                    "token": String,
436
                    "slug": String,
437
                    "publishURL": String,
438
                    "createdAt": String,
439
                    "updatedAt": String,
440
                    "__v": Number,
441
                    "password": String,
442
                }`);
443
                expect(responseBody.password).to.equal('password');
444
            });
445
446
            it('should check project password', async function() {
447
                const client = await getUnauthenticatedTestClient();
448
449
                const correctPasswordResponse = await client.checkProjectPassword(
450
                    testProjectId,
451
                    'password'
452
                );
453
                expect(correctPasswordResponse.statusCode).to.equal(200);
454
455
                const incorrectPasswordResponse = await client.checkProjectPassword(
456
                    testProjectId,
457
                    'password1'
458
                );
459
                expect(incorrectPasswordResponse.statusCode).to.equal(401);
460
            });
461
        });
462
463
        describe('Publish', function() {
464
            it('should set project publish to true', async function() {
465
                const client = await getAuthenticatedTestClient();
466
                const response = await client.publishProject(testProjectId);
467
468
                const responseBody = response.json;
469
470
                expect(response.statusCode).to.equal(200);
471
                expect(responseBody).to.matchPattern(`{
472
                    "_id": String,
473
                    "title": String,
474
                    "fonts": Array,
475
                    "publish": Boolean,
476
                    "secure": Boolean,
477
                    "countViews": Number,
478
                    "timeViews": Number,
479
                    "priority": Number,
480
                    "blocks": Array,
481
                    "userId": String,
482
                    "accountId": String,
483
                    "token": String,
484
                    "slug": String,
485
                    "publishURL": String,
486
                    "createdAt": String,
487
                    "updatedAt": String,
488
                    "__v": Number,
489
                    "password"?: String,
490
                }`);
491
                expect(responseBody.publish).to.equal(true);
492
            });
493
        });
494
495
        describe('Secure', function() {
496
            it('should set project secure to true', async function() {
497
                const client = await getAuthenticatedTestClient();
498
                const response = await client.secureProject(testProjectId);
499
500
                const responseBody = response.json;
501
502
                expect(response.statusCode).to.equal(200);
503
                expect(responseBody).to.matchPattern(`{
504
                    "_id": String,
505
                    "title": String,
506
                    "fonts": Array,
507
                    "publish": Boolean,
508
                    "secure": Boolean,
509
                    "countViews": Number,
510
                    "timeViews": Number,
511
                    "priority": Number,
512
                    "blocks": Array,
513
                    "userId": String,
514
                    "accountId": String,
515
                    "token": String,
516
                    "slug": String,
517
                    "publishURL": String,
518
                    "createdAt": String,
519
                    "updatedAt": String,
520
                    "__v": Number,
521
                    "password"?: String,
522
                }`);
523
                expect(responseBody.secure).to.equal(true);
524
            });
525
        });
526
527
        describe('Cover', function() {
528
            it('should generate project cover', async function() {
529
                const client = await getAuthenticatedTestClient();
530
                const response = await client.generateProjectCover(testProjectId);
531
532
                expect(response.statusCode).to.equal(200);
533
            });
534
        });
535
536
        describe('Copy', function() {
537
            it('should generate project based on a default template', async function() {
538
                const templateId = '5cb47ec98497e9001ad9a1b2';
539
                const client = await getAuthenticatedTestClient();
540
                const response = await client.createProjectFromTemplate(templateId);
541
542
                const responseBody = response.json;
543
544
                expect(response.statusCode).to.equal(200);
545
                expect(responseBody).to.matchPattern(`{
546
                    "_id": String,
547
                    "title": String,
548
                    "fonts": Array,
549
                    "publish": Boolean,
550
                    "secure": Boolean,
551
                    "countViews": Number,
552
                    "timeViews": Number,
553
                    "priority": Number,
554
                    "blocks": Array,
555
                    "userId": String,
556
                    "accountId": String,
557
                    "token": String,
558
                    "slug": String,
559
                    "publishURL": String,
560
                    "createdAt": String,
561
                    "updatedAt": String,
562
                    "__v": Number,
563
                    "password"?: any,
564
                }`);
565
            });
566
        });
567
568
        describe('View and Notify', function() {
569
            it('should update project last view time and send email with notification only if is not the project owner viewing', async function() {
570
                const client = await getUnauthenticatedTestClient();
571
                const response = await client.viewProjectAndNotify(testProjectId);
572
573
                // const responseBody = response.json;
574
575
                expect(response.statusCode).to.equal(200);
576
                // expect(responseBody.emailSent).to.equal(true);
577
            });
578
        });
579
580
        describe('Templates', function() {
581
            it('should list templates thar the user can use paginated', async function() {
582
                const client = await getAuthenticatedTestClient();
583
                const response = await client.listTemplates();
584
585
                const responseBody = response.json;
586
                const templates = responseBody.items;
587
588
                expect(response.statusCode).to.equal(200);
589
                expect(responseBody).to.matchPattern(`{
590
                    "items": Array,
591
                    "totalItems": Number,
592
                    "page": Number,
593
                    "limit": Number,
594
                    "pages": Number,
595
                    "defaultCover": String,
596
                    "lastView"?: String,
597
                }`);
598
                templates.forEach(template => {
599
                    expect(template).to.matchPattern(`{
600
                        "_id": String,
601
                        "title": String,
602
                        "fonts": Array,
603
                        "publish": Boolean,
604
                        "secure": Boolean,
605
                        "countViews": Number,
606
                        "timeViews": Number,
607
                        "priority": Number,
608
                        "blocks": Array,
609
                        "userId": String,
610
                        "accountId": String,
611
                        "token": String,
612
                        "slug": String,
613
                        "publishURL": String,
614
                        "createdAt": String,
615
                        "updatedAt": String,
616
                        "__v": Number,
617
                        "password"?: String OR null,
618
                        "cover"?: String,
619
                        "currency"?: String,
620
                        "heating"?: Object,
621
                        "lastView": String,
622
                    }`);
623
                });
624
            });
625
        });
626
627
        describe('Remove', function() {
628
            it('should delete a existing project', async function() {
629
                const client = await getAuthenticatedTestClient();
630
                const newProject = await client.createProject({
631
                    title: 'New Project',
632
                    blocks: [],
633
                });
634
635
                const project = JSON.parse(newProject.body);
636
                const projectId = project._id;
637
638
                const response = await client.deleteProject(projectId);
639
640
                expect(response.statusCode).to.equal(204);
641
            });
642
        });
643
    });
644
645
    describe('Block', function() {
646
        var testBlockId = null;
647
648
        describe('List Project Blocks', function() {
649
            it('should list project blocks', async function() {
650
                const projectId = '5ca344b1df6272001ae7d7ac';
651
                const client = await getAuthenticatedTestClient();
652
                const response = await client.listBlocks(projectId);
653
654
                const blocks = response.json;
655
656
                expect(response.statusCode).to.equal(200);
657
                blocks.forEach(block => {
658
                    expect(block).to.matchPattern(`{
659
                        "_id": String,
660
                        "style": Object,
661
                        "fullScreen": Boolean,
662
                        "rows": Array,
663
                        "description": String,
664
                        "createdAt": String,
665
                        "updatedAt": String,
666
                    }`);
667
                });
668
            });
669
        });
670
671
        describe('Create Project Block', function() {
672
            it('should create and return a new project block', async function() {
673
                const projectId = '5ca344b1df6272001ae7d7ac';
674
675
                const client = await getAuthenticatedTestClient();
676
                const response = await client.createBlock(projectId, {
677
                    description: 'New Block',
678
                });
679
680
                const responseBody = response.json;
681
682
                expect(response.statusCode).to.equal(201);
683
                expect(responseBody).to.matchPattern(`{
684
                    "_id": String,
685
                    "style": Object,
686
                    "fullScreen": Boolean,
687
                    "rows": Array,
688
                    "description": String,
689
                    "createdAt": String,
690
                    "updatedAt": String,
691
                }`);
692
                expect(responseBody.description).to.equal('New Block');
693
694
                testBlockId = responseBody._id;
695
            });
696
        });
697
698
        describe('Retrieve Project Block', function() {
699
            it('should return a project block', async function() {
700
                const projectId = '5ca344b1df6272001ae7d7ac';
701
                const blockId = '5cb8698632f905001a024614';
702
703
                const client = await getAuthenticatedTestClient();
704
                const response = await client.listBlock(projectId, blockId);
705
706
                const responseBody = response.json;
707
708
                expect(response.statusCode).to.equal(200);
709
                expect(responseBody).to.matchPattern(`{
710
                    "_id": String,
711
                    "style": Object,
712
                    "fullScreen": Boolean,
713
                    "rows": Array,
714
                    "description": String,
715
                    "createdAt": String,
716
                    "updatedAt": String,
717
                }`);
718
            });
719
        });
720
721
        describe('Update Project Block', function() {
722
            it('should update and return a project block', async function() {
723
                const projectId = '5ca344b1df6272001ae7d7ac';
724
                const blockId = '5cb8698632f905001a024614';
725
726
                const client = await getAuthenticatedTestClient();
727
                const response = await client.updateBlock(projectId, blockId, {
728
                    description: 'Updated Block Description',
729
                });
730
731
                const responseBody = response.json;
732
733
                expect(response.statusCode).to.equal(200);
734
                expect(responseBody).to.matchPattern(`{
735
                    "_id": String,
736
                    "style": Object,
737
                    "fullScreen": Boolean,
738
                    "rows": Array,
739
                    "description": String,
740
                    "createdAt": String,
741
                    "updatedAt": String,
742
                }`);
743
                expect(responseBody.description).to.equal('Updated Block Description');
744
            });
745
        });
746
747
        describe('Move Project Block Forward', function() {
748
            it('should move a project block forward (+1)', async function() {
749
                const projectId = '5ca344b1df6272001ae7d7ac';
750
751
                const client = await getAuthenticatedTestClient();
752
                const response = await client.moveBlockForward(projectId, testBlockId);
753
754
                const responseBody = response.json;
755
756
                expect(response.statusCode).to.equal(200);
757
                expect(responseBody).to.matchPattern(`{
758
                    "_id": String,
759
                    "style": Object,
760
                    "fullScreen": Boolean,
761
                    "rows": Array,
762
                    "description": String,
763
                    "createdAt": String,
764
                    "updatedAt": String,
765
                }`);
766
            });
767
        });
768
769
        describe('Move Project Block Backward', function() {
770
            it('should move a project block forward (-1)', async function() {
771
                const projectId = '5ca344b1df6272001ae7d7ac';
772
773
                const client = await getAuthenticatedTestClient();
774
                const response = await client.moveBlockBackward(projectId, testBlockId);
775
776
                const responseBody = response.json;
777
778
                expect(response.statusCode).to.equal(200);
779
                expect(responseBody).to.matchPattern(`{
780
                    "_id": String,
781
                    "style": Object,
782
                    "fullScreen": Boolean,
783
                    "rows": Array,
784
                    "description": String,
785
                    "createdAt": String,
786
                    "updatedAt": String,
787
                }`);
788
            });
789
        });
790
791
        describe('Clone Project Block', function() {
792
            it('should clone a project block without a specific position', async function() {
793
                const projectId = '5ca344b1df6272001ae7d7ac';
794
795
                const client = await getAuthenticatedTestClient();
796
                const response = await client.cloneBlock(projectId, testBlockId);
797
798
                const responseBody = response.json;
799
800
                expect(response.statusCode).to.equal(201);
801
                expect(responseBody).to.matchPattern(`{
802
                    "_id": String,
803
                    "style": Object,
804
                    "fullScreen": Boolean,
805
                    "rows": Array,
806
                    "description": String,
807
                    "createdAt": String,
808
                    "updatedAt": String,
809
                }`);
810
            });
811
812
            it('should clone a project block and put it in a specific position', async function() {
813
                const projectId = '5ca344b1df6272001ae7d7ac';
814
815
                const client = await getAuthenticatedTestClient();
816
                const response = await client.cloneBlock(projectId, testBlockId, 0);
817
818
                const responseBody = response.json;
819
820
                expect(response.statusCode).to.equal(201);
821
                expect(responseBody).to.matchPattern(`{
822
                    "_id": String,
823
                    "style": Object,
824
                    "fullScreen": Boolean,
825
                    "rows": Array,
826
                    "description": String,
827
                    "createdAt": String,
828
                    "updatedAt": String,
829
                }`);
830
            });
831
        });
832
833
        describe('Remove Project Block', function() {
834
            it('should delete a project block', async function() {
835
                const projectId = '5ca344b1df6272001ae7d7ac';
836
837
                const client = await getAuthenticatedTestClient();
838
                const response = await client.deleteBlock(projectId, testBlockId);
839
840
                expect(response.statusCode).to.equal(204);
841
            });
842
        });
843
    });
844
845
    describe('Row', function() {
846
        var testRowId = null;
847
848
        describe('List Project Block Rows', function() {
849
            it('should list project block rows', async function() {
850
                const projectId = '5ca344b1df6272001ae7d7ac';
851
                const blockId = '5cb8698632f905001a024614';
852
                const client = await getAuthenticatedTestClient();
853
                const response = await client.listRows(projectId, blockId);
854
855
                const rows = response.json;
856
857
                expect(response.statusCode).to.equal(200);
858
                rows.forEach(row => {
859
                    expect(row).to.matchPattern(`{
860
                        "_id": String,
861
                        "description": String,
862
                        "columns": Array,
863
                        "createdAt": String,
864
                        "updatedAt": String,
865
                    }`);
866
                });
867
            });
868
        });
869
870
        describe('Create Project Block Row', function() {
871
            it('should create and return a new project block row', async function() {
872
                const blockId = '5cb8698632f905001a024614';
873
                const projectId = '5ca344b1df6272001ae7d7ac';
874
                const client = await getAuthenticatedTestClient();
875
                const response = await client.createRow(projectId, blockId, {
876
                    description: 'New row',
877
                });
878
879
                const responseBody = response.json;
880
881
                expect(response.statusCode).to.equal(201);
882
                expect(responseBody).to.matchPattern(`{
883
                    "_id": String,
884
                    "description": String,
885
                    "columns": Array,
886
                    "createdAt": String,
887
                    "updatedAt": String,
888
                }`);
889
                expect(responseBody.description).to.equal('New row');
890
891
                testRowId = responseBody._id;
892
            });
893
        });
894
895
        describe('Retrieve Project Block Row', function() {
896
            it('should list a project block row', async function() {
897
                const projectId = '5ca344b1df6272001ae7d7ac';
898
                const blockId = '5cb8698632f905001a024614';
899
                const client = await getAuthenticatedTestClient();
900
                const response = await client.listRow(projectId, blockId, testRowId);
901
902
                const responseBody = response.json;
903
904
                expect(response.statusCode).to.equal(200);
905
                expect(responseBody).to.matchPattern(`{
906
                    "_id": String,
907
                    "description": String,
908
                    "columns": Array,
909
                    "createdAt": String,
910
                    "updatedAt": String,
911
                }`);
912
            });
913
        });
914
915
        describe('Update Project Block Row', function() {
916
            it('should update and return a project block row', async function() {
917
                const blockId = '5cb8698632f905001a024614';
918
                const projectId = '5ca344b1df6272001ae7d7ac';
919
                const client = await getAuthenticatedTestClient();
920
                const response = await client.updateRow(projectId, blockId, testRowId, {
921
                    description: 'Updated row description',
922
                });
923
924
                const responseBody = response.json;
925
926
                expect(response.statusCode).to.equal(200);
927
                expect(responseBody).to.matchPattern(`{
928
                "_id": String,
929
                "description": String,
930
                "columns": Array,
931
                "createdAt": String,
932
                "updatedAt": String,
933
            }`);
934
                expect(responseBody.description).to.equal('Updated row description');
935
            });
936
        });
937
938
        describe('Clone Project Block Row', function() {
939
            it('should clone a project block row without a specific position', async function() {
940
                const projectId = '5ca344b1df6272001ae7d7ac';
941
                const blockId = '5cb8698632f905001a024614';
942
943
                const client = await getAuthenticatedTestClient();
944
                const response = await client.cloneRow(projectId, blockId, testRowId);
945
946
                const responseBody = response.json;
947
948
                expect(response.statusCode).to.equal(201);
949
                expect(responseBody).to.matchPattern(`{
950
                    "_id": String,
951
                    "description": String,
952
                    "columns": Array,
953
                    "createdAt": String,
954
                    "updatedAt": String,
955
                }`);
956
            });
957
958
            it('should clone project block row and put it in a specific position', async function() {
959
                const projectId = '5ca344b1df6272001ae7d7ac';
960
                const blockId = '5cb8698632f905001a024614';
961
962
                const client = await getAuthenticatedTestClient();
963
                const response = await client.cloneRow(projectId, blockId, testRowId, 0);
964
965
                const responseBody = response.json;
966
967
                expect(response.statusCode).to.equal(201);
968
                expect(responseBody).to.matchPattern(`{
969
                    "_id": String,
970
                    "description": String,
971
                    "columns": Array,
972
                    "createdAt": String,
973
                    "updatedAt": String,
974
                }`);
975
            });
976
        });
977
978
        describe('Remove Project Block Row', function() {
979
            it('should delete a project block row', async function() {
980
                const projectId = '5ca344b1df6272001ae7d7ac';
981
                const blockId = '5cb8698632f905001a024614';
982
983
                const client = await getAuthenticatedTestClient();
984
                const response = await client.deleteRow(projectId, blockId, testRowId);
985
986
                expect(response.statusCode).to.equal(204);
987
            });
988
        });
989
    });
990
991
    describe('Column', function() {
992
        var testColumnId = null;
993
994
        describe('List Project Block Row Columns', function() {
995
            it('should list project block row columns', async function() {
996
                const projectId = '5ca344b1df6272001ae7d7ac';
997
                const blockId = '5cb8698632f905001a024614';
998
                const rowId = '5cbf11c97f6a64001aea65f2';
999
                const client = await getAuthenticatedTestClient();
1000
                const response = await client.listColumns(projectId, blockId, rowId);
1001
1002
                const columns = response.json;
1003
1004
                expect(response.statusCode).to.equal(200);
1005
                columns.forEach(column => {
1006
                    expect(column).to.matchPattern(`{
1007
                        "_id": String,
1008
                        "contents": Array,
1009
                        "size": Number,
1010
                        "createdAt": String,
1011
                        "updatedAt": String,
1012
                    }`);
1013
                });
1014
            });
1015
        });
1016
1017
        describe('Create Project Block Row Column', function() {
1018
            it('should create and return a new project block row column', async function() {
1019
                const blockId = '5cb8698632f905001a024614';
1020
                const projectId = '5ca344b1df6272001ae7d7ac';
1021
                const rowId = '5cbf11c97f6a64001aea65f2';
1022
                const client = await getAuthenticatedTestClient();
1023
                const response = await client.createColumn(projectId, blockId, rowId, {
1024
                    contents: [],
1025
                    size: 12,
1026
                });
1027
1028
                const responseBody = response.json;
1029
1030
                expect(response.statusCode).to.equal(201);
1031
                expect(responseBody).to.matchPattern(`{
1032
                    "_id": String,
1033
                    "contents": Array,
1034
                    "size": Number,
1035
                    "createdAt": String,
1036
                    "updatedAt": String,
1037
                }`);
1038
                expect(responseBody.size).to.equal(12);
1039
1040
                testColumnId = responseBody._id;
1041
            });
1042
        });
1043
1044
        describe('Retrieve Project Block Row Column', function() {
1045
            it('should list a project block row column', async function() {
1046
                const projectId = '5ca344b1df6272001ae7d7ac';
1047
                const blockId = '5cb8698632f905001a024614';
1048
                const rowId = '5cbf11c97f6a64001aea65f2';
1049
                const client = await getAuthenticatedTestClient();
1050
                const response = await client.listColumn(projectId, blockId, rowId, testColumnId);
1051
1052
                const responseBody = response.json;
1053
1054
                expect(response.statusCode).to.equal(200);
1055
                expect(responseBody).to.matchPattern(`{
1056
                    "_id": String,
1057
                    "contents": Array,
1058
                    "size": Number,
1059
                    "createdAt": String,
1060
                    "updatedAt": String,
1061
                }`);
1062
            });
1063
        });
1064
1065
        describe('Update Project Block Row Column', function() {
1066
            it('should update and return a project block row column', async function() {
1067
                const blockId = '5cb8698632f905001a024614';
1068
                const projectId = '5ca344b1df6272001ae7d7ac';
1069
                const rowId = '5cbf11c97f6a64001aea65f2';
1070
                const client = await getAuthenticatedTestClient();
1071
                const response = await client.updateColumn(
1072
                    projectId,
1073
                    blockId,
1074
                    rowId,
1075
                    testColumnId,
1076
                    {
1077
                        size: 11,
1078
                    }
1079
                );
1080
1081
                const responseBody = response.json;
1082
1083
                expect(response.statusCode).to.equal(200);
1084
                expect(responseBody).to.matchPattern(`{
1085
                    "_id": String,
1086
                    "contents": Array,
1087
                    "size": Number,
1088
                    "createdAt": String,
1089
                    "updatedAt": String,
1090
                }`);
1091
                expect(responseBody.size).to.equal(11);
1092
            });
1093
        });
1094
1095
        describe('Remove Project Block Row Column', function() {
1096
            it('should delete a project block row column', async function() {
1097
                const blockId = '5cb8698632f905001a024614';
1098
                const projectId = '5ca344b1df6272001ae7d7ac';
1099
                const rowId = '5cbf11c97f6a64001aea65f2';
1100
                const client = await getAuthenticatedTestClient();
1101
1102
                const response = await client.deleteColumn(projectId, blockId, rowId, testColumnId);
1103
1104
                expect(response.statusCode).to.equal(204);
1105
            });
1106
        });
1107
    });
1108
1109
    describe('Content', function() {
1110
        var testContentId = null;
1111
1112
        describe('List Project Block Row Column Contents', function() {
1113
            it('should list project block row column contents', async function() {
1114
                const projectId = '5ca344b1df6272001ae7d7ac';
1115
                const blockId = '5cb8698632f905001a024614';
1116
                const rowId = '5cb8698632f905001a024615';
1117
                const columnId = '5cb869d132f905001a024656';
1118
                const client = await getAuthenticatedTestClient();
1119
                const response = await client.listContents(projectId, blockId, rowId, columnId);
1120
1121
                const contents = response.json;
1122
1123
                expect(response.statusCode).to.equal(200);
1124
                contents.forEach(content => {
1125
                    expect(content).to.matchPattern(`{
1126
                        "_id": String,
1127
                        "type": String,
1128
                        "style": Object,
1129
                        "data": Object,
1130
                        "createdAt": String,
1131
                        "updatedAt": String,
1132
                    }`);
1133
                });
1134
            });
1135
        });
1136
1137
        describe('Create Project Block Row Column Content', function() {
1138
            it('should create and return a new project block row column content', async function() {
1139
                const projectId = '5ca344b1df6272001ae7d7ac';
1140
                const blockId = '5cb8698632f905001a024614';
1141
                const rowId = '5cb8698632f905001a024615';
1142
                const columnId = '5cb869d132f905001a024656';
1143
                const client = await getAuthenticatedTestClient();
1144
                const response = await client.createContent(projectId, blockId, rowId, columnId, {
1145
                    style: {
1146
                        backgroundImage: '',
1147
                        backgroundRepeat: 'no-repeat',
1148
                        backgroundSize: 'cover',
1149
                        backgroundPosition: 'center center',
1150
                        opacity: 1,
1151
                    },
1152
                    type: 'text',
1153
                    data: {
1154
                        json: {
1155
                            type: 'doc',
1156
                            content: [
1157
                                {
1158
                                    type: 'paragraph',
1159
                                    content: [
1160
                                        {
1161
                                            type: 'text',
1162
                                            text: 'Lorem Ipsum',
1163
                                        },
1164
                                    ],
1165
                                },
1166
                            ],
1167
                        },
1168
                        html: '<p style="text-align: center">Lorem Ipsum</p>',
1169
                    },
1170
                });
1171
1172
                const responseBody = response.json;
1173
1174
                expect(response.statusCode).to.equal(201);
1175
                expect(responseBody).to.matchPattern(`{
1176
                    "_id": String,
1177
                    "type": String,
1178
                    "style": Object,
1179
                    "data": Object,
1180
                    "createdAt": String,
1181
                    "updatedAt": String,
1182
                }`);
1183
1184
                testContentId = responseBody._id;
1185
            });
1186
        });
1187
1188
        describe('Retrieve Project Block Row Column Content', function() {
1189
            it('should list a project block row column content', async function() {
1190
                const projectId = '5ca344b1df6272001ae7d7ac';
1191
                const blockId = '5cb8698632f905001a024614';
1192
                const rowId = '5cb8698632f905001a024615';
1193
                const columnId = '5cb869d132f905001a024656';
1194
                const client = await getAuthenticatedTestClient();
1195
                const response = await client.listContent(
1196
                    projectId,
1197
                    blockId,
1198
                    rowId,
1199
                    columnId,
1200
                    testContentId
1201
                );
1202
1203
                const responseBody = response.json;
1204
1205
                expect(response.statusCode).to.equal(200);
1206
                expect(responseBody).to.matchPattern(`{
1207
                    "_id": String,
1208
                    "type": String,
1209
                    "style": Object,
1210
                    "data": Object,
1211
                    "createdAt": String,
1212
                    "updatedAt": String,
1213
                }`);
1214
            });
1215
        });
1216
1217
        describe('Update Project Block Row Column Content', function() {
1218
            it('should update and return a project block row column content', async function() {
1219
                const projectId = '5ca344b1df6272001ae7d7ac';
1220
                const blockId = '5cb8698632f905001a024614';
1221
                const rowId = '5cb8698632f905001a024615';
1222
                const columnId = '5cb869d132f905001a024656';
1223
                const client = await getAuthenticatedTestClient();
1224
                const response = await client.updateContent(
1225
                    projectId,
1226
                    blockId,
1227
                    rowId,
1228
                    columnId,
1229
                    testContentId,
1230
                    {
1231
                        type: 'text',
1232
                        data: {
1233
                            json: {
1234
                                type: 'doc',
1235
                                content: [
1236
                                    {
1237
                                        type: 'paragraph',
1238
                                        content: [
1239
                                            {
1240
                                                type: 'text',
1241
                                                text: 'Lorem Ipsuma',
1242
                                            },
1243
                                        ],
1244
                                    },
1245
                                ],
1246
                            },
1247
                            html: '<p style="text-align: center">Lorem Ipsuma</p>',
1248
                        },
1249
                    }
1250
                );
1251
1252
                const responseBody = response.json;
1253
1254
                expect(response.statusCode).to.equal(200);
1255
                expect(responseBody).to.matchPattern(`{
1256
                    "_id": String,
1257
                    "type": String,
1258
                    "style": Object,
1259
                    "data": Object,
1260
                    "createdAt": String,
1261
                    "updatedAt": String,
1262
                }`);
1263
            });
1264
        });
1265
1266
        describe('Remove Project Block Row Column Content', function() {
1267
            it('should delete a project block row column', async function() {
1268
                const projectId = '5ca344b1df6272001ae7d7ac';
1269
                const blockId = '5cb8698632f905001a024614';
1270
                const rowId = '5cb8698632f905001a024615';
1271
                const columnId = '5cb869d132f905001a024656';
1272
                const client = await getAuthenticatedTestClient();
1273
                const response = await client.deleteContent(
1274
                    projectId,
1275
                    blockId,
1276
                    rowId,
1277
                    columnId,
1278
                    testContentId
1279
                );
1280
1281
                expect(response.statusCode).to.equal(204);
1282
            });
1283
        });
1284
    });
1285
});
1286